package com.hiwan.unions.adapter.fragmentAdapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hiwan.unions.R;

/**
 * Created by llg on 2017/7/7.
 */
public class FragmentAdapter_POP extends BaseAdapter {
    private String[] mDates = {};
    private int[] mImage = {};

    private Context mContext;
    private ViewHolder holder;

    public FragmentAdapter_POP(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mDates.length;
    }

    @Override
    public Object getItem(int position) {
        return mDates[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setDates(String[] mDates, int[] mImage) {
        this.mDates = mDates;
        this.mImage = mImage;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_girdview_pop, null);
            holder.ItemTextView = (TextView) convertView.findViewById(R.id.ItemTextView);
            holder.mImageView = (ImageView) convertView.findViewById(R.id.ItemImageView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        setData(holder, position);
        return convertView;
    }


    /**
     * 设置viewHolder的数据  1型
     *
     * @param holder
     * @param itemIndex
     */
    private void setData(ViewHolder holder, int itemIndex) {
        holder.mImageView.setImageResource(mImage[itemIndex]);
        holder.ItemTextView.setText(mDates[itemIndex]);
    }

    private class ViewHolder {
        private TextView ItemTextView;
        private ImageView mImageView;
    }

}
